class EventEmitter {
  constructor() {
    this.events = this.events | new Map()
  }
  addListener(type, callback) {
    if (!this.events.get(type)) {
      this.events.set(type, callback)
    }
  }

  emit(type) {
    let handle = this.events.get(type)

    handle.apply(this, [...arguments].slice(1))
  }
}

let emmiter = new EventEmitter()

// 监听订阅
emmiter.addListener('building', (e) => {
  console.log('购买', e);
})


// 发布
emmiter.emit('building', 200)


